package com.openbravo.editor;

import com.openbravo.basic.BasicException;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;

public abstract class JEditorAbstract extends JPanel
  implements EditorComponent
{
  private EditorKeys editorkeys;
  private boolean m_bActive;
  private final Border m_borderactive = new CompoundBorder(new LineBorder(UIManager.getDefaults().getColor("TextField.selectionBackground")), new EmptyBorder(new Insets(1, 4, 1, 4)));
  private final Border m_borderinactive = new CompoundBorder(new LineBorder(UIManager.getDefaults().getColor("Button.darkShadow")), new EmptyBorder(new Insets(1, 4, 1, 4)));
  private JLabel m_jMode;
  private JButton m_jText;
  private JPanel panBackground;

  public JEditorAbstract()
  {
    initComponents();
    this.editorkeys = null;
    this.m_bActive = false;
    this.m_jText.setBorder(this.m_borderinactive);
  }

  protected abstract int getMode();

  protected abstract int getAlignment();

  protected abstract String getEditMode();

  protected abstract String getTextEdit();

  protected abstract String getTextFormat()
    throws BasicException;

  protected abstract void typeCharInternal(char paramChar);

  protected abstract void transCharInternal(char paramChar);

  public void typeChar(char paramChar)
  {
    typeCharInternal(paramChar);
    reprintText();
    firePropertyChange("Edition", null, null);
  }

  public void transChar(char paramChar)
  {
    transCharInternal(paramChar);
    reprintText();
    firePropertyChange("Edition", null, null);
  }

  public void addEditorKeys(EditorKeys paramEditorKeys)
  {
    this.editorkeys = paramEditorKeys;
  }

  public void deactivate()
  {
    setActive(false);
  }

  public Component getComponent()
  {
    return this;
  }

  public void activate()
  {
    if (isEnabled())
    {
      this.editorkeys.setActive(this, getMode());
      setActive(true);
    }
  }

  private void setActive(boolean paramBoolean)
  {
    this.m_bActive = paramBoolean;
    this.m_jText.setBorder(this.m_bActive ? this.m_borderactive : this.m_borderinactive);
    reprintText();
  }

  protected void reprintText()
  {
    this.m_jText.setHorizontalAlignment(getAlignment());
    if (this.m_bActive)
    {
      this.m_jMode.setText(getEditMode());
      this.m_jText.setText(getTextEdit());
      this.m_jText.setForeground(UIManager.getDefaults().getColor("Label.foreground"));
    }
    else
    {
      this.m_jMode.setText(null);
      try
      {
        this.m_jText.setText(getTextFormat());
        this.m_jText.setForeground(UIManager.getDefaults().getColor("Label.foreground"));
      }
      catch (BasicException localBasicException)
      {
        this.m_jText.setText(getTextEdit());
        this.m_jText.setForeground(Color.RED);
      }
    }
  }

  public void setEnabled(boolean paramBoolean)
  {
    if (this.editorkeys != null)
      this.editorkeys.setInactive(this);
    this.panBackground.setBackground(paramBoolean ? UIManager.getDefaults().getColor("TextField.background") : UIManager.getDefaults().getColor("TextField.disabledBackground"));
    super.setEnabled(paramBoolean);
  }

  private void initComponents()
  {
    this.panBackground = new JPanel();
    this.m_jText = new JButton();
    this.m_jMode = new JLabel();
    setLayout(new BorderLayout());
    this.panBackground.setBackground(UIManager.getDefaults().getColor("TextField.background"));
    this.panBackground.setLayout(new BorderLayout());
    this.m_jText.setBackground(UIManager.getDefaults().getColor("TextField.background"));
    this.m_jText.setContentAreaFilled(false);
    this.m_jText.setFocusPainted(false);
    this.m_jText.setFocusable(false);
    this.m_jText.setMinimumSize(new Dimension(100, 25));
    this.m_jText.setPreferredSize(new Dimension(100, 25));
    this.m_jText.setRequestFocusEnabled(false);
    this.m_jText.setVerticalAlignment(1);
    this.m_jText.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JEditorAbstract.this.m_jTextActionPerformed(paramActionEvent);
      }
    });
    this.panBackground.add(this.m_jText, "Center");
    add(this.panBackground, "Center");
    this.m_jMode.setFont(new Font("Dialog", 0, 9));
    this.m_jMode.setHorizontalAlignment(0);
    this.m_jMode.setVerticalAlignment(1);
    this.m_jMode.setPreferredSize(new Dimension(32, 0));
    add(this.m_jMode, "After");
  }

  private void m_jTextActionPerformed(ActionEvent paramActionEvent)
  {
    activate();
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.editor.JEditorAbstract
 * JD-Core Version:    0.6.0
 */